package com.akiokevin.plantyourlife.database;

import java.util.ArrayList;
import java.util.List;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Environment;

import com.akiokevin.plantyourlife.schedule.ScheduleEntry;
import com.akiokevin.plantyourlife.schedule.ScheduleEntryResult;

public class ScheduleDBHelper extends SQLiteOpenHelper {
	private SQLiteDatabase db;
	private Context context;
	
	private static final String DB_PATH = Environment.getDataDirectory() + "/data/data/com.akiokevin.plantyourlife/databases/";
	private static final String DB_NAME = "pylDB";
	private static final String CREATE_TEMPLATE_TABLE = "CREATE TABLE template(_id INTEGER PRIMARY KEY, content TEXT, time TEXT, result TEXT)";
	private static final String CREATE_HISTORY_TABLE = "CREATE TABLE history(_id INTEGER PRIMARY KEY, period TEXT, score INTEGER)";
	private static final String CREATE_RESULT_TABLE = "CREATE TABLE result(_id INTEGER PRIMARY KEY, date TEXT, result TEXT)";
	
	
	
	public ScheduleDBHelper(Context context) {
		super(context, DB_NAME, null, 1);
		this.context = context;
	}
	
	@Override
	public void onCreate(SQLiteDatabase arg0) {
		db.execSQL(CREATE_TEMPLATE_TABLE);
		db.execSQL(CREATE_HISTORY_TABLE);
		db.execSQL(CREATE_RESULT_TABLE);
		
		insertInitialTemplate();
	}

	private void insertInitialTemplate() {
		ContentValues cv = null; 
			
		cv = createTemplateContentValues(1, "Wake up", "6:30", "PENDING");
		db.insert("template", null, cv);
		
		cv = createTemplateContentValues(2, "Eat breakfast", "7:30", "PENDING");
		db.insert("template", null, cv);
		
		cv = createTemplateContentValues(3, "Eat lunch", "13:0", "PENDING");
		db.insert("template", null, cv);
		
		cv = createTemplateContentValues(4, "Eat dinner", "19:0", "PENDING");
		db.insert("template", null, cv);
		
		cv = createTemplateContentValues(5, "Go to bed", "23:30", "PENDING");
		db.insert("template", null, cv);
	}
	
	
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub

	}
	
	public void close() {
		db.close();
	}
	
	private ContentValues createTemplateContentValues(int id, String content, String time, String result) {
		ContentValues values = new ContentValues();
		values.put("_id", id);
		values.put("content", content);
		values.put("time", time);
		values.put("result", result);
		return values;
	}
}
